package cn.flying.base.process.mapper;



import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import cn.flying.base.process.model.CfProcBizConfig;


/**
 * @description: 流程配置
 * @author: lvyong
 * @date: 2023年02月21日 18:28
 * @version: 1.0
 */
@Mapper
public interface ProcessBizConfigMapper {

    /**
     * 保存流程业务配置关系
     *
     * @param config
     */
    @Insert("insert into cf_proc_config (id,biz_code,biz_name,proc_def_key,remark,tenant_id,revision,created_by,created_time,updated_by,updated_time,del_flag) " +
            "values(#{id}, #{bizCode}, #{bizName}, #{procDefKey}, #{remark}, #{tenantId}, #{revision}, #{createdBy}, #{createdTime}, #{updatedBy}, #{updatedTime}, #{delFlag})")
    void insert(CfProcBizConfig config);


    /**
     * 查询所有的业务流程配置
     *
     * @param bizConfig
     * @return
     */
    @Select("<script> select id,biz_code,biz_name,proc_def_key,remark,tenant_id,updated_by,updated_time from cf_proc_config " +
            "<where>" +
            "<if test='bizCode != null and bizCode != \"\"'> and biz_code = #{bizCode} </if>" +
            "<if test='procDefKey != null and procDefKey != \"\"'> and proc_def_key = #{procDefKey} </if>" +
            "<if test='tenantId != null and tenantId != \"\"'> and tenant_id = #{tenantId} </if>" +
            "</where>" +
            "</script>")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "bizCode", column = "biz_code"),
            @Result(property = "bizName", column = "biz_name"),
            @Result(property = "procDefKey", column = "proc_def_key"),
            @Result(property = "remark", column = "remark"),
            @Result(property = "tenantId", column = "tenant_id"),
            @Result(property = "updatedBy", column = "updated_by"),
            @Result(property = "updatedTime", column = "updated_time"),
    })
    List<CfProcBizConfig> getProcessBizConfigPageList(CfProcBizConfig bizConfig);

    /**
     * 查询流程业务配置
     *
     * @param bizCode
     * @return
     */
    @Select("select id,biz_code,biz_name,proc_def_key,remark,tenant_id,updated_by,updated_time from cf_proc_config where biz_code = #{bizCode}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "bizCode", column = "biz_code"),
            @Result(property = "bizName", column = "biz_name"),
            @Result(property = "procDefKey", column = "proc_def_key"),
            @Result(property = "remark", column = "remark"),
            @Result(property = "tenantId", column = "tenant_id"),
            @Result(property = "updatedBy", column = "updated_by"),
            @Result(property = "updatedTime", column = "updated_time"),
    })
    CfProcBizConfig getProcBizConfig(String bizCode);

}
